//
//  HYAuthorView.m
//  HaiYue
//
//  Created by skyline on 2018/2/6.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYAuthorView.h"
@interface HYAuthorView()
@property (nonatomic, strong) HYImageView *iconIMG;
@property (nonatomic, strong) HYLabel *authorLBL;
@property (nonatomic, strong) HYLabel *timeLBL;
@property (nonatomic, strong) HYView *line;
@end
@implementation HYAuthorView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.bounds = CGRectMake(0, 0, 0, GAP * 2);
    }
    return self;
}

- (HYImageView *)iconIMG
{
    if (!_iconIMG)
    {
        _iconIMG = [[HYImageView alloc] initWithImage:nil cornerRadius:3];
        _iconIMG.bounds = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height);
        [self addSubview:_iconIMG];
        [_iconIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(self.iconIMG.bounds.size);
        }];
    }
    return _iconIMG;
}

- (HYLabel *)authorLBL
{
    if (!_authorLBL)
    {
        _authorLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:11 weight:UIFontWeightLight]];
        [self addSubview:_authorLBL];
        [_authorLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconIMG.mas_right).with.offset(GAP / 2.0);
            make.centerY.equalTo(self.iconIMG);
        }];
    }
    return _authorLBL;
}

- (HYView *)line
{
    if (!_line)
    {
        _line = [[HYView alloc] initWithColor:CELL_LINE_COLOR];
        [self addSubview:_line];
        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorLBL.mas_right).with.offset(GAP / 2.0);
            make.top.equalTo(self.iconIMG).with.offset(HYOnlineCellLBL_Gap);
            make.bottom.equalTo(self.iconIMG).with.offset(-HYOnlineCellLBL_Gap);
            make.width.mas_equalTo(1);
        }];
    }
    return _line;
}

- (HYLabel *)timeLBL
{
    if (!_timeLBL)
    {
        _timeLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:11 weight:UIFontWeightLight]];
        [self addSubview:_timeLBL];
        [_timeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.line.mas_right).with.offset(GAP / 2.0);
            make.centerY.equalTo(self.iconIMG);
        }];
    }
    return _timeLBL;
}

- (void)setDict:(NSDictionary *)dict
{
    if (_dict != dict)
    {
        _dict = dict;
        self.iconIMG.image = [UIImage imageNamed:[_dict valueForKey:@"icon"]];
        self.authorLBL.text = [_dict valueForKey:@"author"];
        self.timeLBL.text = [_dict valueForKey:@"time"];
        self.bounds = CGRectMake(0, 0, self.iconIMG.bounds.size.width + self.authorLBL.bounds.size.width + self.timeLBL.bounds.size.width + GAP * 2.5 + 1, self.bounds.size.height);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
